import sgmllib

class MyParser(sgmllib.SGMLParser):
    "A simple parser class."

    def parse(self, s, domain):
        "Parse the given string 's'."
        self.CurrentDomain = domain
        self.feed(s)
        self.close()

    def __init__(self, verbose=1):
        "Initialise an object, passing 'verbose' to the superclass."

        sgmllib.SGMLParser.__init__(self, verbose)
        self.CurrentPage = ""
        self.TestQuerys = []
        self.inside_form_element = 0
        
    def start_form(self, attributes):
    	print " *** Inizio Form"
        "Process a form and its 'attributes'."
        for name, value in attributes:
            #print name
            if name == "id":
                print "Nome Form = " + value
            if name == "action":
                print "Pagina Linkata = " + value
                self.CurrentPage = value
                
    def start_input (self, attributes):	
        #if self.inside_form_element:
        for name, value in attributes:
            if name == "id":
                print "Valore passato alla pagina = " + value
                self.TestQuerys.append(self.CurrentDomain + "/" + self.CurrentPage + "?" + value + "='")
                #self.descriptions.append(value)



    def end_form(self):
        "Record the end of a form"
        self.inside_form_element = 0
        print " *** Fine Form"

    def get_TestQuerys(self):
        "Return the list of hyperlinks."

        return self.TestQuerys

import urllib, sgmllib

# Get something to work with.
dominio = "http://www.punto-informatico.it"
f = urllib.urlopen(dominio)
s = f.read()

# Try and process the page.
# The class should have been defined first, remember.
myparser = MyParser()
myparser.parse(s,dominio)

print myparser.get_TestQuerys()
